import { fakeChartData, fakeTableData } from '@/services/home';
import { doRobotList } from '@/services/robotManagement';
import { doStatInfo, doHotQuestion } from '@/services/home';

export default {
  namespace: 'home',
  state: {
    visitorTup: {},
    chatCountTup: {},
    matchRateTup: {},
    unknownCountTup: {},
    hitCountTup: {},
    items: [],
    total: '',
    loading: false,
  },

  effects: {
    *fetchRobotList({ payload, callback }, { call, put }) {
      const response = yield call(doRobotList, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchStatInfo({ payload, callback }, { call, put }) {
      const response = yield call(doStatInfo, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchHotQuestion({ payload, callback }, { call, put }) {
      const response = yield call(doHotQuestion, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        visitorTup: {},
        chatCountTup: {},
        matchRateTup: {},
        unknownCountTup: {},
        hitCountTup: {},
        items: [],
        total: '',
      };
    }
  },
};
